<template>
  <div>第三方登入中...</div>
</template>
<script>
import { mapGetters } from 'vuex';
export default {
  name: 'img-login',
  computed: {
    ...mapGetters(['tagWel', 'userInfo'])
  },
  data() {
    return {
      tenantId: '',
      code: ''
    };
  },
  created() {
    this.tenantId = this._get(this.$route.query, 'tenant', '');
    this.code = this._get(this.$route.query, 'code', '');
    this.getPrams(this.tenantId, this.code);
  },
  methods: {
    /**
     * 获取地址回掉参数
     * @param value
     */
    getPrams(tenantId, code) {
      let prams = {
        tenantId: tenantId,
        code: code,
        grant_type: 'imc',
        source: 'huawei_imc'
      };
      this.handleLogin(prams);
    },
    handleLogin(loginForm) {
      this.$store
        .dispatch('LoginByImc', loginForm)
        .then(() => {
          if (this.website.switchMode) {
            const deptId = this.userInfo.dept_id;
            const roleId = this.userInfo.role_id;
            if (deptId.includes(',') || roleId.includes(',')) {
              this.loginForm.deptId = deptId;
              this.loginForm.roleId = roleId;
              this.userBox = true;
              this.$store.dispatch('LogOut').then(() => {});
              return false;
            }
          }
          this.$router.push({ path: this.tagWel.value });
        })
        .catch(() => {
          this.$router.replace('/login');
        });
    }
  }
};
</script>
